package com.wilmer.papers.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wilmer.common.core.domain.entity.SysUser;
import com.wilmer.papers.domain.InitiateTestVO;
import com.wilmer.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.papers.domain.YwPapers;
import com.wilmer.papers.service.IYwPapersService;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.common.core.page.TableDataInfo;

/**
 * 试卷作业Controller
 *
 * @author zl
 * @date 2024-04-18
 */
@Api(tags = "试卷作业-接口")
@RestController
@RequestMapping("/papers/papers")
public class YwPapersController extends BaseController {
    @Autowired
    private IYwPapersService ywPapersService;
    @Autowired
    private ISysUserService userService;

    @ApiOperation("查看 考试教师人")
    @GetMapping({"/selectTeacher/{paperId}"})
    public AjaxResult selectTeacher(@PathVariable Long paperId) {
        List<SysUser> sysUsers = this.userService.selectTeacher(paperId);
        return this.success(sysUsers);
    }

    @ApiOperation("发起考试（admin可以选全部人  幼儿园能选院内教师）发起")
    @PreAuthorize("@ss.hasPermi('papers:papers:initiateTest')")
    @PostMapping({"/initiateTest"})
    public AjaxResult initiateTest(@RequestBody InitiateTestVO initiateTestVO) {
        return this.success(this.ywPapersService.initiateTest(initiateTestVO));
    }

    @ApiOperation("查询试卷作业详情（题和选项）")
    @PreAuthorize("@ss.hasPermi('papers:papers:info')")
    @GetMapping({"/getInfo/{paperId}"})
    public AjaxResult getInfoAll(@PathVariable Long paperId) {
        YwPapers ywPapers = this.ywPapersService.selectYwPapersAll(paperId);
        return this.success(ywPapers);
    }

    @PreAuthorize("@ss.hasPermi('papers:papers:list')")
    @GetMapping({"/list"})
    public TableDataInfo list(YwPapers ywPapers) {
        this.startPage();
        List<YwPapers> list = this.ywPapersService.selectYwPapersList(ywPapers);
        return this.getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('papers:papers:export')")
    @Log(
            title = "试卷作业",
            businessType = BusinessType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, YwPapers ywPapers) {
        List<YwPapers> list = this.ywPapersService.selectYwPapersList(ywPapers);
        ExcelUtil<YwPapers> util = new ExcelUtil(YwPapers.class);
        util.exportExcel(response, list, "试卷作业数据");
    }

    @PreAuthorize("@ss.hasPermi('papers:papers:query')")
    @GetMapping({"/{paperId}"})
    public AjaxResult getInfo(@PathVariable("paperId") Long paperId) {
        return this.success(this.ywPapersService.selectYwPapersByPaperId(paperId));
    }

    @PreAuthorize("@ss.hasPermi('papers:papers:add')")
    @Log(
            title = "试卷作业",
            businessType = BusinessType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody YwPapers ywPapers) {
        return this.toAjax(this.ywPapersService.insertYwPapers(ywPapers));
    }

    @PreAuthorize("@ss.hasPermi('papers:papers:edit')")
    @Log(
            title = "试卷作业",
            businessType = BusinessType.UPDATE
    )
    @PutMapping
    public AjaxResult edit(@RequestBody YwPapers ywPapers) {
        return this.toAjax(this.ywPapersService.updateYwPapers(ywPapers));
    }

    @PreAuthorize("@ss.hasPermi('papers:papers:remove')")
    @Log(
            title = "试卷作业",
            businessType = BusinessType.DELETE
    )
    @DeleteMapping({"/{paperIds}"})
    public AjaxResult remove(@PathVariable Long[] paperIds) {
        return this.toAjax(this.ywPapersService.deleteYwPapersByPaperIds(paperIds));
    }
//    /**
//     * 查看 考试教师人
//     */
//    @ApiOperation("查看 考试教师人")
//    @GetMapping("/selectTeacher/{paperId}")
//    public AjaxResult selectTeacher(@PathVariable Long paperId) {
//        List<SysUser> sysUsers = userService.selectTeacher(paperId);
//        return success(sysUsers);
//    }
//
//    /**
//     * 选择人发起考试（admin可以选全部人  幼儿园能选院内教师）发起
//     */
//    @ApiOperation("发起考试（admin可以选全部人  幼儿园能选院内教师）发起")
//    @PreAuthorize("@ss.hasPermi('papers:papers:initiateTest')")
//    @PostMapping("/initiateTest")
//    public AjaxResult initiateTest(@RequestBody InitiateTestVO initiateTestVO) {
//        return success(ywPapersService.initiateTest(initiateTestVO));
//    }
//    /**
//     * 查询试卷作业详情（题和选项）
//     */
//    @ApiOperation("查询试卷作业详情（题和选项）")
//    @PreAuthorize("@ss.hasPermi('papers:papers:info')")
//    @GetMapping("/getInfo/{paperId}")
//    public AjaxResult getInfoAll(@PathVariable Long paperId) {
//        YwPapers ywPapers = ywPapersService.selectYwPapersAll(paperId);
//        return success(ywPapers);
//    }
//    /**
//     * 查询试卷作业列表
//     */
//    @PreAuthorize("@ss.hasPermi('papers:papers:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(YwPapers ywPapers)
//    {
//        startPage();
//        List<YwPapers> list = ywPapersService.selectYwPapersList(ywPapers);
//        return getDataTable(list);
//    }
//
//    /**
//     * 导出试卷作业列表
//     */
//    @PreAuthorize("@ss.hasPermi('papers:papers:export')")
//    @Log(title = "试卷作业", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, YwPapers ywPapers)
//    {
//        List<YwPapers> list = ywPapersService.selectYwPapersList(ywPapers);
//        ExcelUtil<YwPapers> util = new ExcelUtil<YwPapers>(YwPapers.class);
//        util.exportExcel(response, list, "试卷作业数据");
//    }
//
//    /**
//     * 获取试卷作业详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('papers:papers:query')")
//    @GetMapping(value = "/{paperId}")
//    public AjaxResult getInfo(@PathVariable("paperId") Long paperId)
//    {
//        return success(ywPapersService.selectYwPapersByPaperId(paperId));
//    }
//
//    /**
//     * 新增试卷作业
//     */
//    @PreAuthorize("@ss.hasPermi('papers:papers:add')")
//    @Log(title = "试卷作业", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody YwPapers ywPapers)
//    {
//        return toAjax(ywPapersService.insertYwPapers(ywPapers));
//    }
//
//    /**
//     * 修改试卷作业
//     */
//    @PreAuthorize("@ss.hasPermi('papers:papers:edit')")
//    @Log(title = "试卷作业", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody YwPapers ywPapers)
//    {
//        return toAjax(ywPapersService.updateYwPapers(ywPapers));
//    }
//
//    /**
//     * 删除试卷作业
//     */
//    @PreAuthorize("@ss.hasPermi('papers:papers:remove')")
//    @Log(title = "试卷作业", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{paperIds}")
//    public AjaxResult remove(@PathVariable Long[] paperIds)
//    {
//        return toAjax(ywPapersService.deleteYwPapersByPaperIds(paperIds));
//    }
}
